package com.datastructure.test.movezeroes;

public class MoveZeroes {

    public static void main(String[] args) {
        MoveZeroes moveZeroes = new MoveZeroes();
        int[] nums = {0,0,0};
        int[] zeroes = moveZeroes.moveZeroes(nums);
        System.out.println(zeroes);
    }

    public int[] moveZeroes (int[] nums) {
        // write code here
        int time = 0;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i]==0){
                time++;
            } else {
                if(time>0){
                    int j = i;
                    for(int k =0;k<time;k++,j--){
                        swap(nums,j,j-1);
                    }
                }
            }
        }
        return nums;
    }

    public void swap(int[] nums,int i,int j){
        int temp = nums[i];
        nums[i]=nums[j];
        nums[j]=temp;
    }
}
